#include<bits/stdc++.h>
using namespace std;

struct node {
	char data;
	node *lc, *rc;
};

string inOrd, postOrd;
int n;

node* in_and_post(int in_l, int in_r, int post_l, int post_r) {
	if (in_l > in_r || post_l > post_r)
		return NULL;

	node *T = new node;
	T->data = postOrd[post_r];
	T->lc = T->rc = NULL;

	for (int i = in_l; i <= in_r; i++) {
		if (inOrd[i] == postOrd[post_r]) {
			T->lc = in_and_post(in_l, i - 1, post_l, post_l + i - in_l - 1);
			T->rc = in_and_post(i + 1, in_r, post_l + i - in_l, post_r - 1);
		}
	}
	return T;
}

void dlr(node* T) {
	if (T) {
		cout << T->data;
		dlr(T->lc);
		dlr(T->rc);
	}
}

signed main() {
	cin >> inOrd >> postOrd;
	n = inOrd.size();
	dlr(in_and_post(0, n - 1, 0, n - 1));
	return 0;
}
